<?php
/*
 * 手机客户端 秀场我的粉丝
 * 传入参数 
 * 2013-12-011
 */
include "inc/public_header.php";
include "func/user.php";				//用户信息处理函数

//头像根路径
$LOGO_BASE_PATH = "http://www.chinalaohu.com/modules/miniature.php?w=150&h=150&p=/uploads/zjl_ilogo/";

//默认头像
$LOGO_DEFAULT_PATH = "http://www.chinalaohu.com/images/zjl/logo.png";

//获取用户信息
$uInfoArr = user_getInfoFromUUID();
if(!$uInfoArr){
	echo json_encode(array("success"=>"0","errCode"=>"0","msg"=>"没有获取到用户信息"));
	die;
}
$uid = $uInfoArr["uid"];//用户信息主键


$reJson = array();//构建返回值
 
$page			= $_REQUEST["page"]; 			//页数，第一页为0
$pagesize		= $_REQUEST["pagesize"];		//每页记录数
$hd_id			= $_REQUEST["hd_id"];			//活动主键

if(!isset($page)){
	$page = 0;
}
if(!isset($pagesize)){
	$pagesize = 20; //默认每页10条
}

$reJson["success"] = "1";

//获取粉丝总数
$sql = "select count(0) as ct from user_base a inner join new_weituo_fensi b on a.uid=b.uid where b.uid='".$uid."'";
if(isset($hd_id) && $hd_id!=""){
	$sql .= " and b.hd_id='".$hd_id."' ";
}
$db->query($sql);
$db->next_record();
$reJson["count"] = $db->f("ct");


$sql="
select 

		c.fuid 
		,c.uid
		,b.nickname as nickname
		,b.ilogo_path as userIcon
		,b.xuexiao as userCollege
		,e.ct as attention
		,d.ct as fans
		,f.ct as works
		,a.mobile
		,g.id as guanzhu	 

from 
	
		user_base a 
		left join new_weituo_person b on a.uid=b.uid
		inner join new_weituo_fensi c on a.uid=c.fuid
		left join (select uid,count(id) as ct from new_weituo_fensi ";
if(isset($hd_id) && $hd_id!=""){
	$sql .= " where hd_id='".$hd_id."' ";
}
$sql .=" group by uid) d on d.uid=c.fuid
		left join (select fuid,count(id) as ct from new_weituo_fensi ";
if(isset($hd_id) && $hd_id!=""){
	$sql .= " where hd_id='".$hd_id."' ";
}
$sql .="  group by fuid) e on e.fuid=c.fuid
		left join (select uid,count(id) as ct from new_weituo_zuopin where dr='0' and aflag='1' ";
if(isset($hd_id) && $hd_id!=""){
	$sql .= " and hd_id='".$hd_id."' ";
}
$sql .=" group by uid) f on f.uid=c.fuid

		left join (select uid,id from new_weituo_fensi where fuid='".$uid."'";
		if(isset($hd_id) && $hd_id!=""){
	$sql .= " and hd_id='".$hd_id."' ";
}
$sql .="  ) g on g.uid=c.fuid
where 
		c.uid='".$uid."' ";
if(isset($hd_id) && $hd_id!=""){
	$sql .= " and hd_id='".$hd_id."' ";
}

//获取关注我的人的信息列表
/*
$sql = "
	select 
		 
        b.nickname
		,c.uid
		,c.fuid
        ,b.ilogo_path as userIcon
        ,b.xuexiao as userCollege
        ,d.ct as attention
        ,e.ct as fans
        ,f.ct as works
		,a.mobile
		,g.id as guanzhu
    from 
      
        user_base a 
        left join new_weituo_person b on a.uid=b.uid
        inner join new_weituo_fensi c on a.uid=c.uid
        left join (select uid,count(id) as ct from new_weituo_fensi ";
if(isset($hd_id) && $hd_id!=""){
	$sql .= " where hd_id='".$hd_id."' ";
}
$sql .=" group by uid) d on d.uid=c.uid
        left join (select fuid,count(id) as ct from new_weituo_fensi ";
if(isset($hd_id) && $hd_id!=""){
	$sql .= " where hd_id='".$hd_id."' ";
}
$sql .=" group by fuid) e on e.fuid=c.uid
        left join (select uid,count(id) as ct from new_weituo_zuopin where dr='0' and aflag='1'";
if(isset($hd_id) && $hd_id!=""){
	$sql .= " and hd_id='".$hd_id."' ";
}
$sql .= "group by uid) f on f.uid=c.uid
        left join (select fuid,id from new_weituo_fensi where uid='".$uid."'";
if(isset($hd_id) && $hd_id!=""){
	$sql .= " and hd_id='".$hd_id."' ";
}
$sql .=" ) g on g.fuid=c.uid
        where c.uid='".$uid."'";
if(isset($hd_id) && $hd_id!=""){
	$sql .= " and c.hd_id='".$hd_id."' ";
}*/
$sql = $sql." limit ".($page * $pagesize).",".$pagesize;
$fansArr=array();
$db->query($sql);
while($db->next_record()){

	$nickName = $db->f("nickname");
	if($nickName==null){
		$nickName = user_fix_mobile($db->f("mobile"));
	}
	$userCollege = $db->f("userCollege");
	if($userCollege==null){
		$userCollege = "";
	}
	$userIcon = $db->f("userIcon");
	$hasILogo = "0"; //是否存在头像
	if($userIcon==null){
		//默认头像
		$userIcon = $LOGO_DEFAULT_PATH;
	}else{
		$userIcon = $LOGO_BASE_PATH.$userIcon;
		$hasILogo = "1";	
	}
	//是否关注了粉丝
	$guanzhu = $db->f("guanzhu");
	if($guanzhu==null){
		$guanzhu = "0";
	}else{
		$guanzhu = "1";
	}
	$fansArr[] = array(
		 "userIcon"		=>	$userIcon			//用户头像
		,"userName"		=>	$nickName			//昵称
		,"userCollege"	=>	$userCollege		//学校
		,"attention"	=>	$db->f("attention")==null?"0":$db->f("attention")	//关注数（ta关注的人数）
		,"fans"			=>	$db->f("fans")==null?"0":$db->f("fans")				//关注ta的人数
		,"works"		=>	$db->f("works")==null?"0":$db->f("works")			//ta的作品数
		,"userId"		=>	$db->f("fuid")		//用户主键
		,"guanzhu"		=>	$guanzhu			//是否关注了粉丝
		,"has_ilogo"	=>	$hasILogo			//用户是否设置了头像 0没设置  1设置
	);
}

$reJson["list"]=$fansArr;
echo json_encode($reJson);

?>